package com.example.im.ui.fragment

import android.content.Context
import android.os.Bundle
import android.view.View
import com.example.im.R
import com.example.im.bean.UserRoom
import com.example.im.callback.OnClickUserListener
import com.example.im.mvp.base.BasePresenter
import com.example.im.ui.abstracts.AbstractBaseFragment
import com.example.im.common.Constants
import kotlinx.android.synthetic.main.fragment_user_center.*

class UserCentreFragment : AbstractBaseFragment<BasePresenter<*>>(), View.OnClickListener {


    private var user: UserRoom? = null

    private var mOnClickUserListener: OnClickUserListener? = null

    companion object {
        fun newInstance(user: UserRoom): UserCentreFragment {
            val bundle = Bundle()
            bundle.putSerializable(Constants.BUNDLE_T0_USER_ROOM_DATA, user)
            val fragment = UserCentreFragment()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        mOnClickUserListener = context as OnClickUserListener
    }

    override val layoutId: Int
        get() = R.layout.fragment_user_center

    override fun initView() {

        this.user = arguments?.getSerializable(Constants.BUNDLE_T0_USER_ROOM_DATA)
                as UserRoom

        tv_user_nick_name_1.text = user?.nickname
        tv_user_nick_name_2.text = user?.nickname
        tv_user_name.text = user?.account

        tv_user_send_chat.setOnClickListener(this)
        tv_user_clear_chat.setOnClickListener(this)
        tv_user_delete.setOnClickListener(this)

    }

    override fun initPresenter() {

    }

    override fun initLazyLoad() {

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_user_send_chat ->
                mOnClickUserListener?.onClickSendChat(v, user ?: return)
            R.id.tv_user_clear_chat ->
                mOnClickUserListener?.onClickClearChat(v, user ?: return)
            R.id.tv_user_delete ->
                mOnClickUserListener?.onClickDelete(v, user ?: return)
        }
    }

}